package com.example.demo.nuoqi.service.impl;

import com.example.demo.nuoqi.dao.InviteapplicationMapper;
import com.example.demo.nuoqi.pojo.Inviteapplication;
import com.example.demo.nuoqi.service.InviteapplicationService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/****
 * @Author:shenkunlin
 * @Description:Inviteapplication业务层接口实现类
 * @Date 2019/6/14 0:16
 *****/
@Service
public class InviteapplicationServiceImpl implements InviteapplicationService {

    @Autowired
    private InviteapplicationMapper inviteapplicationMapper;


    /**
     * Inviteapplication条件+分页查询
     * @param inviteapplication 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public PageInfo<Inviteapplication> findPage(Inviteapplication inviteapplication, int page, int size){
        //分页
        PageHelper.startPage(page,size);
        //搜索条件构建
        Example example = createExample(inviteapplication);
        //执行搜索
        return new PageInfo<Inviteapplication>(inviteapplicationMapper.selectByExample(example));
    }

    /**
     * Inviteapplication分页查询
     * @param page
     * @param size
     * @return
     */
    @Override
    public PageInfo<Inviteapplication> findPage(int page, int size){
        //静态分页
        PageHelper.startPage(page,size);
        //分页查询
        return new PageInfo<Inviteapplication>(inviteapplicationMapper.selectAll());
    }

    /**
     * Inviteapplication条件查询
     * @param inviteapplication
     * @return
     */
    @Override
    public List<Inviteapplication> findList(Inviteapplication inviteapplication){
        //构建查询条件
        Example example = createExample(inviteapplication);
        //根据构建的条件查询数据
        return inviteapplicationMapper.selectByExample(example);
    }


    /**
     * Inviteapplication构建查询对象
     * @param inviteapplication
     * @return
     */
    public Example createExample(Inviteapplication inviteapplication){
        Example example=new Example(Inviteapplication.class);
        Example.Criteria criteria = example.createCriteria();
        if(inviteapplication!=null){
            // 
            if(!StringUtils.isEmpty(inviteapplication.getId())){
                    criteria.andEqualTo("id",inviteapplication.getId());
            }
            // 
            if(!StringUtils.isEmpty(inviteapplication.getItemName())){
                    criteria.andEqualTo("itemName",inviteapplication.getItemName());
            }
            // 
            if(!StringUtils.isEmpty(inviteapplication.getItemId())){
                    criteria.andEqualTo("itemId",inviteapplication.getItemId());
            }
            // 
            if(!StringUtils.isEmpty(inviteapplication.getInvitePerson())){
                    criteria.andEqualTo("InvitePerson",inviteapplication.getInvitePerson());
            }
            // 
            if(!StringUtils.isEmpty(inviteapplication.getCreateTime())){
                    criteria.andEqualTo("createTime",inviteapplication.getCreateTime());
            }
            // 
            if(!StringUtils.isEmpty(inviteapplication.getStatus())){
                    criteria.andEqualTo("status",inviteapplication.getStatus());
            }
            // 
            if(!StringUtils.isEmpty(inviteapplication.getUserId())){
                    criteria.andEqualTo("userId",inviteapplication.getUserId());
            }
            // 
            if(!StringUtils.isEmpty(inviteapplication.getUserName())){
                    criteria.andEqualTo("userName",inviteapplication.getUserName());
            }
        }
        return example;
    }

    /**
     * 删除
     * @param id
     */
    @Override
    public void delete(Integer id){
        inviteapplicationMapper.deleteByPrimaryKey(id);
    }

    /**
     * 修改Inviteapplication
     * @param inviteapplication
     */
    @Override
    public void update(Inviteapplication inviteapplication){
        inviteapplicationMapper.updateByPrimaryKey(inviteapplication);
    }

    /**
     * 增加Inviteapplication
     * @param inviteapplication
     */
    @Override
    public void add(Inviteapplication inviteapplication){
        inviteapplicationMapper.insert(inviteapplication);
    }

    /**
     * 根据ID查询Inviteapplication
     * @param id
     * @return
     */
    @Override
    public Inviteapplication findById(Integer id){
        return  inviteapplicationMapper.selectByPrimaryKey(id);
    }

    /**
     * 查询Inviteapplication全部数据
     * @return
     */
    @Override
    public List<Inviteapplication> findAll() {
        return inviteapplicationMapper.selectAll();
    }
}
